import React ,{ Component }from 'react';
import { BrowserRouter as Router, Route,Switch, Redirect } from 'react-router-dom';
import Homepage from '../main/Homepage.js';
import Recruitlist from '../components/common/Recruitlist';
import Recruit from '../components/students/Recruit';
import DisplayData from '../components/teacher/DisplayData';
import Auditrecruit from '../components/teacher/Auditrecruit';
import UserHome from '../components/students/UserHome';
import AuditList from '../components/teacher/AuditList';
import NoMatch from '../main/404/NotFound'
class Routers extends Component{
    constructor(){
        super();
        this.state={
            isStudent:true
        }
    }
    componentDidMount(){
        let roleId=window.localStorage.getItem('roleId');
        if(roleId==1||roleId==2)
        {
            this.setState({
                isStudent:false
            })
        }else{
            this.setState({
                isStudent:true
            })
        }
    }
    render(){
        return(
            <Router>
                <Switch>
                <Route path='/enroll' render = { () =>
                    {
                        return this.state.isStudent? <Switch>
                        <Homepage>
                        <Route path = '/enroll' exact component = {Recruitlist}/>
                        <Route path='/enroll/recruit/:id' exact component={Recruit} />
                        <Route path = '/enroll/UserHome/:id' exact component = {UserHome}/>
                        {/* <Route path="*" component={NoMatch} /> */} 
                        </Homepage>
                    </Switch>: <Switch>
                                <Homepage>
                                <Route path = '/enroll/' exact component = {Recruitlist}/>
                                <Route path = '/enroll/UserHome/:id' exact component = {UserHome}/>
                                <Route path='/enroll/recruit/:id' exact component={Recruit} />
                                <Route path = '/enroll/displaydata/:id' exact component = {DisplayData}/>
                                <Route path = '/enroll/auditrecruit/:id' exact component = {Auditrecruit}/> 
                                <Route path = '/enroll/auditList/' exact component = {AuditList}/>
                                {/* <Route  path="*" component={NoMatch} /> */}
                                
                                </Homepage>
                            </Switch>
                    }
                           
                    }
                    />
               
                </Switch>
            </Router>
        )
    }
}
export default Routers;